package edu.grupo4.appcomedor;
import com.example.appcomedor.R;

import com.restfb.types.FacebookType;
import com.restfb.types.User;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.Parameter;

public class MainActivity extends Activity implements OnClickListener {

    EditText editText1;
    EditText editText2;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actividad_login);

        editText1=(EditText)findViewById(R.id.editText1);
        editText2=(EditText)findViewById(R.id.editText2);
        button=(Button)findViewById(R.id.button);
        
        //Facebook mFacebook = new Facebook("576051705777921");
        
/*        
        String app_ID="576051705777921";
        String app_Secret="816125eca95b5c2cef1ac84258f3ac6c";
        
        String url_facebook="http://www.facebook.com/";
        FacebookClient fc= new DefaultFacebookClient(
"https://graph.facebook.com/oauth/access_token?client_id="+app_ID+"&client_secret="+app_Secret+"&grant_type=client_credentials");
        //"https://graph.facebook.com/oauth/access_token?client_id=576051705777921&client_secret=816125eca95b5c2cef1ac84258f3ac6c&grant_type=client_credentials");        
        String access_token="576051705777921|erFR_6LS02JKLEPUL2e5WqZfji4";
        FacebookClient fbc= new DefaultFacebookClient(access_token);

        User usuario= fbc.fetchObject("me", User.class);
        User userWithMetadata = fbc.fetchObject("me", User.class, Parameter.with("metadata", 1));
        Page page = facebookClient.fetchObject("Comedor ESPOL", Page.class);
        button.setOnClickListener(this);
        System.out.println(txt_user.setText(user.getName()));//OBTENGO EL USUARIO
*/
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View arg0){
        switch(arg0.getId()){
            case R.id.button:
                String user=editText1.getText().toString();
                String pswd=editText2.getText().toString();
                if(user.equals("Administrador")&&pswd.equals("123456"))
                {
                    //Mostrar pantalla-Actividad
                    Intent int1= new Intent("edu.grupo4.appcomedor.Administrador");
                    startActivity(int1);
                }
                else
                {
                    if(user.equals("Dueno")&&pswd.equals("123456")){
                        //Mostrar pantalla-Actividad
                        Intent int1= new Intent("edu.grupo4.appcomedor.Dueno");
                        startActivity(int1);
                    }else{
                        //Toast Presenta un cuadro de dialogo
                        Toast t=Toast.makeText(this,"User o Password Incorrecto",Toast.LENGTH_SHORT);
                        t.show();
                    }
                }
                break;
        }
    }

}
